package com.lh.controller.dev;

import com.aliyuncs.exceptions.ClientException;
import com.lh.domain.Info;
import com.lh.domain.vo.InfoQuery;
import com.lh.service.InfoService;
import com.lh.utils.alTool.FileDownload;
import com.lh.utils.alTool.FileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.File;

/**
 * @Author LH
 * @Date 2023/11/2 9:00
 * @PackageName com.lh.controller.dev
 * @Description: [项目名小写 多个单词用_分隔 | 包名全部小写 | 类 首字母大写 | 变量和方法 首字母小写，多个单词组成时除首字母，其他字母首字母需大写 | 常量 全部大写,多个单词用'_'分割]
 */
@Controller
@RequestMapping("/dev/flatform/app/appview")
public class DevView {

    @Autowired
    private InfoService infoService;

    @RequestMapping("/{id}")
    public String viewJsp(@PathVariable Integer id, Model model){
        System.out.println("获取的info--id");
        InfoQuery infoQuery = infoService.selectByIdM(1,id);

        //------本地绝对路径-------
        String pathStart = infoQuery.getLogoLocPath();
        //相对项目路径
        String pathEnd = infoQuery.getLogoPicPath();
        //完整文件所在绝对路径
        String filepath = pathStart+pathEnd;
        File file = new File(filepath);
        if(!file.exists()){
            try {
                new FileDownload().download(pathEnd.replaceFirst("/",""),filepath);
                System.out.println("缺失文件下载成功!,下载成功!");
            } catch (ClientException e) {
                throw new RuntimeException(e);
            }
        }
        //--------------------------

        model.addAttribute("appInfo",infoQuery);
        return "developer/appinfoview";
    }
}
